package com.zhuiyi.homeworkstudent.controller;
import java.util.Date;

import com.zhuiyi.homeworkstudent.entity.Student;
import com.zhuiyi.homeworkstudent.service.StudentService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService studentService;
    @RequestMapping("/searchall")
    public List<Student> getStudentList() {
        return studentService.allStudent();
    }

    @RequestMapping("/add")
    public String add(){

        Student student = new Student();
        student.setUserName("李义");
        student.setUserAccount("liyi");
        student.setUserPassword("123");
        studentService.addStudent(student);

        return "add suceess";
    }
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable int id){
        studentService.deleteStudentById(id);
        return "delete success";
    }
    @RequestMapping("/update")
    public String update(){
        Student student = new Student();
        student.setId(8);
        student.setUserName("毓贤");
        student.setUserAccount("yuxian");
        student.setAvatarUrl("");
        student.setGender(1);
        student.setUserPassword("123456");
        student.setPhone("");
        student.setEmail("");
        student.setUserStatus(0);
        student.setCreateTime(new Date());
        student.setUpdateTime(new Date());
        student.setIsDelete(0);
        student.setUserRole(0);


        studentService.updateStudent(student);
        return "update success";
    }
    @RequestMapping("/search/{id}")
    public Student search(@PathVariable int id){
        Student student = studentService.searchStudentById(id);
        return student;
    }
}
